//import java.util.HashMap;
//import java.util.Arrays;
//import java.util.Map;
public class Solution {

    public ListNode getIntersectionNode(ListNode h1, ListNode h2) {
        if(h1==null||h2==null)  return null;

        ListNode a=h1,b=h2;
        int diff=0;       //计算两链表间的节点差
        while(a!=null){   //h1遍历到尾节点
            diff++;
            a=a.next;
        }

        while(b!=null){   //h2遍历到尾节点
            diff--;
            b=b.next;
        }

        if(a!=b) return null;  //如果不存在交到，返回

        if(diff>=0){   //让a指向长链表，b指向短链表
            a=h1;
            b=h2;
        }
        else{
            a=h2;
            b=h1;
        }
        diff=Math.abs(diff);
        while(diff!=0){
            a=a.next;
            diff--;
        }

        while(a!=b){
            a=a.next;
            b=b.next;
        }
        return a;
    }

}